﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/Default.Master" AutoEventWireup="true"
  CodeBehind="RepositoryList.aspx.cs" Inherits="SaleManagement.Web.Pages.RepositoryList"
  Title="" %>

<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dxhf" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <table width="100%">
    <tr>
      <td class="search_header" colspan="7">
                Danh sách KHO</td>
    </tr>
    <tr>
      <td style="width: 80px;">
        Loại kho:
      </td>
      <td style="width: 200px">
        <dxe:ASPxComboBox Width="180px" ID="cbxSearchedType" ClientInstanceName="cbxSearchedType"
          runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua"
          LoadingPanelText="" TextField="Name" ValueField="Id" ValueType="System.String"
          ImageFolder="~/App_Themes/Aqua/{0}/" ShowShadow="False" DataSourceID="xdsRepositoryType">
          <ValidationSettings>
            <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" Width="14px" />
            <ErrorFrameStyle ImageSpacing="4px">
              <ErrorTextPaddings PaddingLeft="4px" />
            </ErrorFrameStyle>
          </ValidationSettings>
          <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
            UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
            UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" Width="12px" />
          <DropDownButton>
            <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
              UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png"
              Width="9px" />
          </DropDownButton>
        </dxe:ASPxComboBox>
      </td>
      <td>
        <dxe:ASPxButton ID="btnSearch" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
          CssPostfix="Aqua" Text="Tìm kiếm" ClientInstanceName="btnSearch">
          <Image Url="../Images/find.png" />
          <ClientSideEvents Click="function(s,e){onbtnSearch(s,e);e.processOnServer=false;}" />
        </dxe:ASPxButton>
      </td>
    </tr>
  </table>
  <div>
    <dxwgv:ASPxGridView ID="gvRepository" ClientInstanceName="gvRepository" runat="server"
      Width="100%" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" OnCustomCallback="gvRepository_CustomCallback"
      OnCustomJSProperties="gvRepository_CustomJSProperties" OnPageIndexChanged="gvRepository_PageIndexChanged"
      AutoGenerateColumns="False" KeyFieldName="Id" OnHtmlDataCellPrepared="gvRepository_HtmlDataCellPrepared">
      <SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" />
      <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
      </Styles>
      <SettingsLoadingPanel Text="" />
      <SettingsPager>
        <AllButton>
          <Image Height="19px" Width="27px" />
        </AllButton>
        <FirstPageButton>
          <Image Height="19px" Width="23px" />
        </FirstPageButton>
        <LastPageButton>
          <Image Height="19px" Width="23px" />
        </LastPageButton>
        <NextPageButton>
          <Image Height="19px" Width="19px" />
        </NextPageButton>
        <PrevPageButton>
          <Image Height="19px" Width="19px" />
        </PrevPageButton>
      </SettingsPager>
      <Images ImageFolder="~/App_Themes/Aqua/{0}/">
        <HeaderSortDown Height="5px" Width="7px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
        <CollapsedButton Height="15px" Width="15px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
        <ExpandedButton Height="15px" Width="15px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
        <DetailCollapsedButton Height="15px" Width="15px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
        <DetailExpandedButton Height="15px" Width="15px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
        <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
        <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
          Width="19px" />
        <HeaderSortUp Height="5px" Width="7px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
        <FilterRowButton Height="13px" Width="13px" />
        <WindowResizer Height="13px" Width="13px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
      </Images>
      <StylesEditors>
        <ProgressBar Height="25px">
        </ProgressBar>
      </StylesEditors>
      <ImagesEditors>
        <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png"
          Width="19px" />
        <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png"
          Width="19px" />
        <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png"
          Width="9px" />
        <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
          Width="7px" />
        <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
          Width="7px" />
        <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" Width="7px" />
        <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
          UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
          UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" Width="7px" />
      </ImagesEditors>
      <ClientSideEvents EndCallback="function (s,e){ongvRepository_EndCallback(s,e);}" />
      <Columns>
        <dxwgv:GridViewDataTextColumn Name="Command" VisibleIndex="0" Width="60px">
          <DataItemTemplate>
            <img src="../Images/delete.png" onclick="onDelete('<%#Eval("Id") %>')" style="cursor: pointer"
              alt="" />
            <img src="../Images/edit.png" runat="server" id="imgEdit" style="cursor: pointer;"
              alt="" />
          </DataItemTemplate>
          <CellStyle HorizontalAlign="Center">
          </CellStyle>
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="1" Caption="Tên">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataComboBoxColumn Caption="Loại" FieldName="Type" VisibleIndex="2">
          <PropertiesComboBox ValueType="System.String" DataSourceID="xdsRepositoryType" TextField="Name"
            ValueField="Id">
          </PropertiesComboBox>
          <HeaderStyle HorizontalAlign="Center" />
          <CellStyle HorizontalAlign="Left">
          </CellStyle>
        </dxwgv:GridViewDataComboBoxColumn>
        <dxwgv:GridViewDataTextColumn FieldName="Address" VisibleIndex="3" Caption="Địa chỉ">
          <HeaderStyle HorizontalAlign="Center" />
        </dxwgv:GridViewDataTextColumn>
        <dxwgv:GridViewDataTextColumn Caption="Mô tả" FieldName="Description" 
          Visible="False" VisibleIndex="4">
        </dxwgv:GridViewDataTextColumn>
      </Columns>
    </dxwgv:ASPxGridView>
  </div>
  <div style="padding-top: 5px;">
    <dxe:ASPxButton ID="btnAdd" runat="server" Text="Thêm mới" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
      CssPostfix="Aqua" AutoPostBack="False">
      <Image Url="../Images/add.png" />
      <ClientSideEvents Click="function(s, e) {
	onAdd();e.processOnServer = false;}" />
    </dxe:ASPxButton>
  </div>
  <asp:XmlDataSource ID="xdsRepositoryType" runat="server" DataFile="~/App_Data/Status.vi-VN.xml"
    XPath="Status/RepositoryType/Item"></asp:XmlDataSource>
  <dxpc:ASPxPopupControl ID="pcAddRepository" ClientInstanceName="pcAddRepository"
    runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua"
    ImageFolder="~/App_Themes/Aqua/{0}/" Width="430px" PopupHorizontalAlign="WindowCenter"
    PopupVerticalAlign="WindowCenter" HeaderText="Thông tin kho" CloseAction="CloseButton"
    Modal="True">
    <ContentStyle VerticalAlign="Top">
    </ContentStyle>
    <SizeGripImage Height="12px" Width="12px" />
    <SizeGripImage Height="12px" Width="12px"></SizeGripImage>
    <ContentCollection>
      <dxpc:PopupControlContentControl>
        <div>
          <dxe:ASPxLabel ID="lblErrorMessage" ClientInstanceName="lblErrorMessage" runat="server"
            Font-Bold="True" ForeColor="#FF3300" Font-Names="Tahoma" Font-Size="8pt" Font-Strikeout="False">
          </dxe:ASPxLabel>
        </div>
        <table class="">
          <tr>
            <td style="width: 80px">
              Loại kho:
            </td>
            <td>
              <dxe:ASPxComboBox Width="170px" ID="cbxType" ClientInstanceName="cbxType" runat="server"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" LoadingPanelText=""
                TextField="Name" ValueField="Id" ValueType="System.String" ImageFolder="~/App_Themes/Aqua/{0}/"
                ShowShadow="False" DataSourceID="xdsRepositoryType">
                <DropDownButton>
                  <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                    UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png" />
                </DropDownButton>
                <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                  UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                  UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" />
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxComboBox>
            </td>
          </tr>
          <tr>
            <td>
              Tên:
            </td>
            <td>
              <dxe:ASPxTextBox ID="txtName" runat="server" ClientInstanceName="txtName" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                CssPostfix="Aqua" Width="170px">
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxTextBox>
            </td>
          </tr>
          <tr>
            <td>
              Địa chỉ:
            </td>
            <td>
              <dxe:ASPxTextBox ID="txtAddress" ClientInstanceName="txtAddress" runat="server" Width="300px"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                <ValidationSettings>
                  <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxTextBox>
            </td>
          </tr>
          <tr>
            <td>
              Mô tả:
            </td>
            <td>
              <dxe:ASPxMemo ID="mmDescription" runat="server" ClientInstanceName="mmDescription"
                CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Height="71px"
                Width="300px">
                <ValidationSettings>
                  <ErrorImage Url="~/App_Themes/Aqua/Editors/edtError.png" />
                  <ErrorFrameStyle ImageSpacing="4px">
                    <ErrorTextPaddings PaddingLeft="4px" />
                  </ErrorFrameStyle>
                </ValidationSettings>
              </dxe:ASPxMemo>
            </td>
          </tr>
          <tr>
            <td>
            </td>
            <td>
              <div style="float: left;">
                <dxe:ASPxButton ID="btnSave" runat="server" Text="Lưu" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua">
                  <Image Url="../Images/save.png" />
                  <ClientSideEvents Click="function(s, e) {
	                      onSave();}" />
                </dxe:ASPxButton>
              </div>
              <div style="float: left; padding-left: 3px;">
                <dxe:ASPxButton ID="btnCancel" runat="server" Text="Đóng" AutoPostBack="False" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua">
                  <Image Url="../Images/cancel.png" />
                  <ClientSideEvents Click="function(s, e) {
	                          onCancel(); e.processOnServer = false;}" />
                </dxe:ASPxButton>
              </div>
            </td>
          </tr>
        </table>
      </dxpc:PopupControlContentControl>
    </ContentCollection>
    <CloseButtonImage Height="16px" Width="18px" />
    <CloseButtonImage Height="18px" Width="18px"></CloseButtonImage>
    <HeaderStyle Font-Bold="True" ForeColor="#59A1EF" />
  </dxpc:ASPxPopupControl>
  <asp:HiddenField runat="server" ID="hfRepositoryId" />

  <script type="text/javascript" language="javascript">
    function onAdd() {
      resetValue();
      pcAddRepository.Show();
    }

    function onEdit(index) {
      lblErrorMessage.SetText('');
      gvRepository.GetRowValues(index, 'Id;Type;Name;Address;Description;', fillRowValue);
    }

    function onDelete(id) {
      if (confirm('Bạn có chắc là muốn xóa kho này?'))
        gvRepository.PerformCallback('Delete|' + id);
    }

    function onSave() {
      if (checkInput())
      {
        gvRepository.PerformCallback('Save|');
      }
    }

    function onbtnSearch(s, e) {
      gvRepository.PerformCallback('Search|');
    }

    function onCancel() {
      pcAddRepository.Hide();
    }

    function resetValue() {
      lblErrorMessage.SetText('');
      document.getElementById('<%=hfRepositoryId.ClientID %>').value = '';
      cbxType.SetValue(null);
      txtName.SetText('');
      txtAddress.SetText('');
      mmDescription.SetText('');
    }

    function checkInput() {
      var error = '';
      if (cbxType.GetValue() == null) {
        error += '<BR> + ' + 'Loại kho không được bỏ trống'
      }
      
      if (txtName.GetText() == '') {
        error += '<BR> + ' + 'Tên kho không được bỏ trống';
      }
      
      if (error != '') {
        lblErrorMessage.SetText(error);
        return false;
      }
      return true;
    }

    function fillRowValue(values) {
      document.getElementById('<%=hfRepositoryId.ClientID %>').value = values[0];
      cbxType.SetValue(values[1]);
      txtName.SetText(values[2]);
      txtAddress.SetText(values[3]);
      mmDescription.SetText(values[4]);
      pcAddRepository.Show();
    }

    function ongvRepository_EndCallback(s, e) {
      var error = gvRepository.cpInnerError.split('|');
      if (error[0] == 'Save') {
        if (error[1] != '')
          lblErrorMessage.SetText(error[1]);
        else {
          pcAddRepository.Hide();
          alert('Cập nhật thành công');
        }
      }
      else if (error[0] != '') {
        alert(error[0]);
      }

    }
  </script>

</asp:Content>
